package com.webxml;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/con")
public class Context extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        //ServletContxt 在服务器启动时创建 在服务关闭时销毁 服务存在该数据就一直存在 全局统一
        ServletContext servletContext = req.getServletContext();
        //存储数据 取出数据
        servletContext.setAttribute("key","val");
        servletContext.getAttribute("key");
        //获取全局参数
        String encoding = servletContext.getInitParameter("encoding");
        //获取真实路径
        String realPath = servletContext.getRealPath("page/login.html");
        System.out.println(realPath+"?"+encoding);

    }
}
